-- create constraints and indices script

\connect pcweek;

-------------------------
-- create data table indices (41 indices)
-------------------------

select 'starting full indexing run' as message, time(CURRENT_TIMESTAMP) as time;
connecting to new database: pcweek
message                   |time    
--------------------------+--------
starting full indexing run|10:56:00
(1 row)


-------------------------
-- uniques (4 indices)
select 'creating uniques indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating uniques indices|10:56:00
(1 row)


-- alter table uniques add constraint uniques_key_PK_IDX primary key (u_key);
create unique index uniques_signed_IDX on uniques (u_signed);
create unique index uniques_code_CK_IDX on uniques (u_code);
create index uniques_name_IDX on uniques (u_name);

select 'finished creating uniques indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
CREATE
CREATE
message                          |time    
---------------------------------+--------
finished creating uniques indices|10:56:01
(1 row)


-------------------------
-- hundred (6 indices)
select 'creating hundred indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating hundred indices|10:56:01
(1 row)


-- alter table hundred add constraint hundred_key_PK_IDX primary key (h_key);
create index hundred_int_IDX on hundred (h_int);
create index hundred_signed_IDX on hundred (h_signed);
create index hundred_date_IDX on hundred (h_date);
create unique index hundred_code_CK_IDX on hundred (h_code);
create index hundred_name_IDX on hundred (h_name);

select 'finished creating hundred indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
CREATE
CREATE
CREATE
CREATE
message                          |time    
---------------------------------+--------
finished creating hundred indices|10:56:03
(1 row)


-------------------------
-- tenpct (9 indices)
select 'creating tenpct indices' as message, time(CURRENT_TIMESTAMP) as time;
message                |time    
-----------------------+--------
creating tenpct indices|10:56:03
(1 row)


-- alter table tenpct add constraint tenpct_key_code_PK_IDX primary key (t_key, t_code);
create index tenpct_int_IDX on tenpct (t_int);
create index tenpct_signed_IDX on tenpct (t_signed);
create index tenpct_float_IDX on tenpct (t_float);
create index tenpct_double_IDX on tenpct (t_double);
create index tenpct_decim_IDX on tenpct (t_decim);
ERROR:  Can't find a default operator class for type 1700.
create index tenpct_date_IDX on tenpct (t_date);
create unique index tenpct_code_CK_IDX on tenpct (t_code);
create index tenpct_name_IDX on tenpct (t_name);

select 'finished creating tenpct indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
CREATE
CREATE
CREATE
CREATE
CREATE
CREATE
message                         |time    
--------------------------------+--------
finished creating tenpct indices|10:56:05
(1 row)


-------------------------
-- updates (6 indices, 1 foreign key)
select 'creating updates indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating updates indices|10:56:05
(1 row)


-- alter table updates add constraint updates_key_PK_IDX primary key (p_key);
create index updates_int_IDX on updates (p_int);
-- foreign key constraints not supported by PostgreSQL yet
-- alter table updates add constraint updates_int_FK foreign key (p_int) references hundred (h_key);
create index updates_signed_IDX on updates (p_signed);
create index updates_decim_IDX on updates (p_decim);
ERROR:  Can't find a default operator class for type 1700.
create index updates_date_IDX on updates (p_date);
create unique index updates_code_CK_IDX on updates (p_code);

select 'finished creating updates indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
CREATE
CREATE
CREATE
message                          |time    
---------------------------------+--------
finished creating updates indices|10:56:07
(1 row)


-------------------------
-- tenthou (5 indices)
select 'creating tenthou indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating tenthou indices|10:56:07
(1 row)


-- alter table tenthou add constraint tenthou_key_code_PK_IDX primary key (t_key, t_code);
create index tenthou_signed_IDX on tenthou (t_signed);
create index tenthou_decim_IDX on tenthou (t_decim);
ERROR:  Can't find a default operator class for type 1700.
create unique index tenthou_code_CK_IDX on tenthou (t_code);
create index tenthou_name_IDX on tenthou (t_name);

select 'finished creating tenthou indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
CREATE
CREATE
message                          |time    
---------------------------------+--------
finished creating tenthou indices|10:56:07
(1 row)


-------------------------
-- hunthou (1 index)
select 'creating hunthou indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating hunthou indices|10:56:07
(1 row)


create index hunthou_signed_IDX on hunthou (h_signed);

select 'finished creating hunthou indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
message                          |time    
---------------------------------+--------
finished creating hunthou indices|10:56:07
(1 row)


-------------------------
-- twomill (3 indices)
select 'creating twomill indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating twomill indices|10:56:07
(1 row)


-- alter table twomill add constraint twomill_key_PK_IDX primary key (p_key);
create index twomill_date_IDX on twomill (p_date);
create unique index twomill_code_CK_IDX on twomill (p_code);

select 'finished creating twomill indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
CREATE
message                          |time    
---------------------------------+--------
finished creating twomill indices|10:56:09
(1 row)


-------------------------
-- threemill (2 indices)
select 'creating threemill indices' as message, time(CURRENT_TIMESTAMP) as time;
message                   |time    
--------------------------+--------
creating threemill indices|10:56:09
(1 row)


-- alter table threemill add constraint threemill_key_PK_IDX primary key (t_key);
create index threemill_signed_IDX on threemill (t_signed);

select 'finished creating threemill indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
message                            |time    
-----------------------------------+--------
finished creating threemill indices|10:56:10
(1 row)


-------------------------
-- fourmill (2 indices)
select 'creating fourmill indices' as message, time(CURRENT_TIMESTAMP) as time;
message                  |time    
-------------------------+--------
creating fourmill indices|10:56:10
(1 row)


-- alter table fourmill add constraint fourmill_key_PK_IDX primary key (t_key);
create index fourmill_name_IDX on fourmill (t_name);

select 'finished creating fourmill indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
message                           |time    
----------------------------------+--------
finished creating fourmill indices|10:56:12
(1 row)


-------------------------
-- fivemill (2 indices)
select 'creating fivemill indices' as message, time(CURRENT_TIMESTAMP) as time;
message                  |time    
-------------------------+--------
creating fivemill indices|10:56:12
(1 row)


-- alter table fivemill add constraint fivemill_key_PK_IDX primary key (h_key);
create unique index fivemill_code_CK_IDX on fivemill (h_code);

select 'finished creating fivemill indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
message                           |time    
----------------------------------+--------
finished creating fivemill indices|10:56:15
(1 row)


-------------------------
-- fourram (1 index)
select 'creating fourram indices' as message, time(CURRENT_TIMESTAMP) as time;
message                 |time    
------------------------+--------
creating fourram indices|10:56:15
(1 row)


-- alter table fourram add constraint fourram_key_PK_IDX primary key (p_key);

select 'finished creating fourram indices' as message, time(CURRENT_TIMESTAMP) as time;
message                          |time    
---------------------------------+--------
finished creating fourram indices|10:56:15
(1 row)


-------------------------
-- create housekeeping table indices (5 indices)
-------------------------

-- update_int_history (2 indices)
select 'creating update_int_history indices' as message, time(CURRENT_TIMESTAMP) as time;
message                            |time    
-----------------------------------+--------
creating update_int_history indices|10:56:15
(1 row)


-- alter table update_int_history add constraint up_int_hist_key_int_PK_IDX primary key (p_key, p_int);
create index update_int_history_int_IDX on update_int_history (p_int);

select 'finished creating update_int_history indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
message                                     |time    
--------------------------------------------+--------
finished creating update_int_history indices|10:56:15
(1 row)


-- update_signed_history (2 indices)
select 'creating update_signed_history indices' as message, time(CURRENT_TIMESTAMP) as time;
message                               |time    
--------------------------------------+--------
creating update_signed_history indices|10:56:15
(1 row)


-- alter table update_signed_history add constraint up_sign_hist_key_sign_PK_IDX primary key (p_key, p_signed);
create index up_sign_hist_sign_IDX on update_signed_history (p_signed);

select 'finished creating update_signed_history indices' as message, time(CURRENT_TIMESTAMP) as time;
CREATE
message                                        |time    
-----------------------------------------------+--------
finished creating update_signed_history indices|10:56:15
(1 row)


-- del_history (1 index)
select 'creating del_history indices' as message, time(CURRENT_TIMESTAMP) as time;
message                     |time    
----------------------------+--------
creating del_history indices|10:56:15
(1 row)


-- alter table del_history add constraint del_history_key_PK_IDX primary key (h_key);

select 'finished creating del_history indices' as message, time(CURRENT_TIMESTAMP) as time;
message                              |time    
-------------------------------------+--------
finished creating del_history indices|10:56:15
(1 row)


-------------------------
-- end
-------------------------

select 'finished full indexing run' as message, time(CURRENT_TIMESTAMP) as time;
message                   |time    
--------------------------+--------
finished full indexing run|10:56:15
(1 row)


\q
